import path from 'path';
import { UPLOADS_DIR } from 'src/constants';

export const uniqueFilename = (file: {
  fieldname: string;
  originalname: string;
}) => {
  const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9);
  const ext = path.extname(file.originalname);
  return `${file.fieldname}-${uniqueSuffix}${ext}`;
};

export const uploadDatePath = () => {
  const date = new Date();
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
  const day = String(date.getDate()).padStart(2, '0');

  return path.join(UPLOADS_DIR, path.join(String(year), month, day));
};
